package A01Mangner;

public class StudentUpdate {
    private String username;
    private String password;
    private String IDcard;
    private String userphonenum;

    public StudentUpdate() {
    }

    public StudentUpdate(String username, String password, String IDcard, String userphonenum) {
        this.username = username;
        this.password = password;
        this.IDcard = IDcard;
        this.userphonenum = userphonenum;
    }

    public String getUsername() {
        return username;
    }

    public boolean setUsername(String username) {
        if(username.length()>=3&&username.length()<=15&&userNameCheck(username)) {
            this.username = username;
            return true;
        }
        else{
            System.out.println("用户名格式错误 应为3-15位字母数字组合");
            return false;
        }
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getIDcard() {
        return IDcard;
    }

    public boolean setIDcard(String IDcard) {
        if(IDcard.length()==18&&userCardCheck(IDcard)){
            this.IDcard = IDcard;
            return true;
        }
        return false;

    }

    public String getUserphonenum() {
        return userphonenum;
    }

    public boolean setUserphonenum(String userphonenum) {
        if(userphonenum.length()==11&&userphonenum.charAt(0)!='0'&&userPhoneCheck(userphonenum)) {
            this.userphonenum = userphonenum;
            return true;
        }
        return false;
    }


    public boolean userNameCheck(String username){
        for(int i=0;i<username.length();i++){
            char ch = username.charAt(i);
            if(ch<'0' || (ch>'9'&&ch<'A')||(ch>'Z'&&ch<'a')||ch>'z'){
                return false;
            }
        }
        return true;
    }
    public boolean userCardCheck(String IDcard){
        for(int i=0;i<IDcard.length()-1;i++){
            char ch = IDcard.charAt(i);
            if(ch<='0' && ch>='9'){
                return false;
            }
        }
        char ch = IDcard.charAt(IDcard.length()-1);
        if((ch>='0' && ch<='9')||ch=='x'||ch=='X'){
            return true;
        }
        return false;
    }
    public boolean userPhoneCheck(String userphonenum){
        for(int i=0;i<userphonenum.length();i++){
            char ch = userphonenum.charAt(i);
            if(ch<='0' && ch>='9'){
                return false;
            }
        }
        return true;
    }
}
